package com.dgut.crm.system.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.dgut.crm.common.util.enumType.Status;

@Entity
@Table(name="role")
public class Role {
	private Long id;
	
	private String name;
	private Date createTime;
	private Status status; //启用状态：0:表示禁用；1:表示启用，默认0
	private List<Number> numbers = new ArrayList<Number>();
	private List<Menu> menus = new ArrayList<Menu>();
	
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}
	
	@Column(length=20,unique=true,nullable=false)
	public String getName() {
		return name;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateTime() {
		return createTime;
	}
	
	public Status getStatus() {
		return status;
	}
	
	@ManyToMany(mappedBy="roles",fetch=FetchType.LAZY)
	public List<Number> getNumbers() {
		return numbers;
	}
	
	@ManyToMany
	@JoinTable(name="role_menu",
		joinColumns=@JoinColumn(name="role_id"),
		inverseJoinColumns=@JoinColumn(name="menu_id")
	)
	public List<Menu> getMenus() {
		return menus;
	}

	public void setId(Long id) {
		this.id = id;
	}
	public void setName(String name) {
		this.name = name;
	}
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	public void setNumbers(List<Number> numbers) {
		this.numbers = numbers;
	}
	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}

	public Role() {
		super();
	}
	public Role(Long id, String name, Date createTime, Status status) {
		super();
		this.id = id;
		this.name = name;
		this.createTime = createTime;
		this.status = status;
	}
	@Override
	public String toString() {
		return "Role [id=" + id + ", name=" + name + ", createTime=" + createTime + ", status=" + status + "]";
	}
}
